package com.huizhonglm.diap.core.upgrade;

import android.content.Context;
import android.content.Intent;

import com.bruce.common.utils.FileUtil;
import com.huizhonglm.diap.core.utils.SdcardUtil;

/**
 * 升级工具类
 *
 * @author LiXiaoLong
 * @version 1.0
 * @since 2016-03-03 10:14
 */
public final class Upgrade {

    public static void doUpgrade(Context context, String mode, String url, String version) {
        String path = SdcardUtil.getTempPath() + "download/";
        String name = "DIAP_V" + version + "_" + System.currentTimeMillis() + ".APK";
        FileUtil.createDir(path);
        Intent intent = new Intent(context, DownloaderService.class);
        intent.putExtra("download_url", url);
        intent.putExtra("local_path", path + name);
        intent.putExtra("update_mode", mode);
        intent.putExtra("notification_id", (int) (Math.random() * 1024));
        context.startService(intent);
    }
}
